package cn.bigway.app.weavingdesigner.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.SwingWorker;

import cn.bigway.app.weavingdesigner.Resources;
import cn.bigway.app.weavingdesigner.type.WdMenuItemType;

abstract public class WdAction extends AbstractAction {

	private static final long serialVersionUID = 5193291927036668535L;

	abstract protected void actionWork();

	public WdAction(WdMenuItemType type) {
		super(Resources.getString(type, "name"), Resources.getIcon(type));

		putValue(MNEMONIC_KEY, Resources.getInteger(type, "mnemonic_key"));
		putValue(SHORT_DESCRIPTION,
				Resources.getString(type, "short_description"));
	}

	@Override
	final public void actionPerformed(ActionEvent event) {
		SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
			@Override
			protected Void doInBackground() throws Exception {
				try {
					actionWork();
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}

			@Override
			protected void done() {
				try {
					actionDone();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		worker.execute();
	}

	protected void actionDone() {
		// TODO Auto-generated method stub
	}
}

// TODO 对于长时间操作要显示等待条 (文字+动画)（dialog + status 栏） ； actionwork前 显示 ； actionDone后隐藏
